package org.stwy.lease.contract;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.stwy.comm.base.BaseRecordsEntity;
import org.stwy.custom.CustomEntity;
import org.stwy.pro.asset.AssetEntity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.rap.common.annotation.MetaData;
import com.rap.common.entity.AuditableEntity;
import com.rap.common.entity.BaseEntity;
import com.rap.frame.enumdata.EnumDataSubEntity;
import com.rap.modules.sys.userrole.UserRoleEntity;

/**
*版权信息 (c) RAP 保留所有权利.
*@author Rap.Codegen
*@Team RAP Team
*@Date 2015-4-17 20:48:15
*<p></p>
*
*@参与人：Rap.Codegen
*/
 
@MetaData(value = "合同")
@Entity
@Table(name = "stwy_contract")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class ContractEntity extends BaseRecordsEntity {
	private static final long serialVersionUID = 1L;
	public static final String CONTRACT_STATE_VALID = "1";//有效
	public static final String CONTRACT_STATE_INVALID = "2";//无效
	
	public static final String CONTRACT_CHANGE_TYPE_ADD = "1";//签订
	public static final String CONTRACT_CHANGE_TYPE_EDIT = "2";//修改
	public static final String CONTRACT_CHANGE_TYPE_RENEW = "3";//续签
	public static final String CONTRACT_CHANGE_TYPE_QUIT = "4";//退租
	public static final String CONTRACT_CHANGE_TYPE_CANCEL = "5";//解除
	public static final String CONTRACT_CHANGE_TYPE_END = "6";//终止
	
	public static final String CONTRACT_PAY_TYPE_MONTH = "1";//月结
	public static final String CONTRACT_PAY_TYPE_QUATER = "2";//季度结
	public static final String CONTRACT_PAY_TYPE_HALFYEAR = "3";//半年结
	public static final String CONTRACT_PAY_TYPE_YEAR = "4";//年结
	public static final String CONTRACT_PAY_TYPE_ONETIME = "5";//一次性
	
	public static final String CONTRACT_INCREASE_TYPE_PERCENT = "1";//增幅类型-百分比
	public static final String CONTRACT_INCREASE_TYPE_YUAN = "2";//增幅类型-金额
	
	public static final String CONTRACT_INCREASE_HANDLE_HOLD = "1";//增幅方式-整体
	public static final String CONTRACT_INCREASE_HANDLE_EVERY = "2";//增幅方式-每平方
	
	
	@MetaData(value = "合同编号",comments="" )
	@Column(nullable = false,length = 50)
	private String contractNum;
	
	@MetaData(value = "承租人",comments="" )
	@ManyToOne(optional=false)
	@JoinColumn(name = "customId")
	private CustomEntity custom;
	
	@MetaData(value = "签订日期",comments="" )
	@Column(nullable = true)
	@Temporal(TemporalType.DATE)
	private Date signDate;
	
	@MetaData(value = "生效日期",comments="" )
	@Column(nullable = false)
	@Temporal(TemporalType.DATE)
	private Date beginDate;
	
	@MetaData(value = "失效日期",comments="" )
	@Column(nullable = false)
	@Temporal(TemporalType.DATE)
	private Date endDate;
	
	@MetaData(value = "租赁期限",comments="合同一共多少个月" )
	@Column(nullable = true)
	private Integer months;
	
	@MetaData(value = "支付类型",enumType="stwy_payType",comments="按月、季度、年、一次性付款" )
	@Column(nullable = false,length=4)
	private String payType;
	
	@MetaData(value = "提前交租天数",comments="整数" )
	@Column(nullable = true)
	private Integer beforeDay;
	
	@MetaData(value = "租金单价",comments="每平方的价格" )
	@Column(nullable = true)
	private Double price;
	
	@MetaData(value = "租金",comments="整体租金" )
	@Column(nullable = true)
	private Double rent;
	
	@MetaData(value = "自动算租起始日")
	@Column(nullable = true)
	@Temporal(TemporalType.DATE)
	private Date autoCalDate;
	
	@MetaData(value = "签合同时是否交租金", enumType="BooleanType")
	@Column(nullable = true)
	private Boolean hasInitPay=true;
	
	@MetaData(value = "签合同时已交租金金额")
	@Column(nullable = true)
	private Double initPay;
	
	/*@MetaData(value = "已交租金支付日期",comments="默认是合同签订日期")
	@Column(nullable = false)
	@Temporal(TemporalType.DATE)
	private Date initPayDate;*/
	
	@MetaData(value = "签合同时租金已交至",comments="指合同签订时缴纳的租金是到哪一天的")
	@Column(nullable = true)
	@Temporal(TemporalType.DATE)
	private Date initPayEndDate;
	
	
	@MetaData(value = "初次调租日期",comments="" )
	@Column(nullable = true)
	@Temporal(TemporalType.DATE)
	private Date adjustDate;
	
	@MetaData(value = "租金涨幅方式",comments="每平方，整体", enumType="stwy_increaseHandle" )
	@Column(nullable = true)
	private String increaseHandle;
	
	@MetaData(value = "租金涨幅",comments="" )
	@Column(nullable = true)
	private Double increase;
	
	@MetaData(value = "租金涨幅类型",comments="百分比，固定金额", enumType="stwy_increaseType")
	@Column(nullable = true,length=4)
	private String increaseType;
	
	@MetaData(value = "租赁保证金",comments="" )
	@Column(nullable = true)
	private Double deposit;
	
	@MetaData(value = "是否已备案",comments="" ,enumType="stwy_hasArchives")
	@Column(nullable = true,length=4)
	private String hasArchives;
	
	@MetaData(value = "备注",comments="" )
	@Column(nullable = true,length=1000)
	private String remark;
	
	@MetaData(value = "合同状态",enumType="stwy_contractState",comments="有效，无效" )
	@Column(nullable = false,length=4)
	private String contractState;
	
	@MetaData(value = "合同变更类型",enumType="stwy_contractChangeType",comments="签订，修改，续签，退租，解除，终止" )
	@Column(nullable = false,length=4)
	private String contractChangeType;
	
	@MetaData(value = "变更原因",comments="" )
	@Column(nullable = true,length=1000)
	private String reason;
	
	@MetaData(value = "承租总面积",comments="" )
	@Column(nullable = true)
	private Double area;
	
	@JsonIgnore
	@OneToMany(mappedBy = "contract", cascade = CascadeType.REMOVE)
	private List<ContractAssetEntity> contractAsset = new ArrayList<ContractAssetEntity>();
	
	@MetaData(value = "一级组别",comments="",enumType="stwy_groupOne")
	@Column(nullable = true,length = 4)
	private String groupOne;
	
	@MetaData(value = "二级组别",comments="",enumType="stwy_groupTwo")
	@Column(nullable = true,length = 4)
	private String groupTwo;
	
	@MetaData(value = "政府指导价",comments="")
	private Double govPrice;
	
	@MetaData(value = "市场指导价",comments="")
	@Column(nullable = true,length = 100)
	private String marketPrice;
	
	/**
	 * 合同编号
	 */
	public String getContractNum(){
		return this.contractNum;
	}
	public void setContractNum(String contractNum){
		this.contractNum = contractNum;
	}
	/**
	 * 承租人
	 */
	public CustomEntity getCustom() {
		return custom;
	}
	public void setCustom(CustomEntity custom) {
		this.custom = custom;
	}
	/**
	 * 起效日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+08:00")
	public Date getBeginDate(){
		return this.beginDate;
	}
	
	public void setBeginDate(Date beginDate){
		this.beginDate = beginDate;
	}
	/**
	 * 失效日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+08:00")
	public Date getEndDate(){
		return this.endDate;
	}
	public void setEndDate(Date endDate){
		this.endDate = endDate;
	}
	
	public Integer getMonths() {
		return months;
	}
	public void setMonths(Integer months) {
		this.months = months;
	}
	public String getPayType() {
		return payType;
	}
	public void setPayType(String payType) {
		this.payType = payType;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	public Double getInitPay() {
		return initPay;
	}
	public void setInitPay(Double initPay) {
		this.initPay = initPay;
	}
/*	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+08:00")
	public Date getInitPayDate() {
		return initPayDate;
	}
	public void setInitPayDate(Date initPayDate) {
		this.initPayDate = initPayDate;
	}*/
	public String getIncreaseType() {
		return increaseType;
	}
	public void setIncreaseType(String increaseType) {
		this.increaseType = increaseType;
	}
	/**
	 * 租金调价日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+08:00")
	public Date getAdjustDate(){
		return this.adjustDate;
	}
	public void setAdjustDate(Date adjustDate){
		this.adjustDate = adjustDate;
	}
	/**
	 * 租金涨幅
	 */
	public Double getIncrease(){
		return this.increase;
	}
	public void setIncrease(Double increase){
		this.increase = increase;
	}
	/**
	 * 租赁保证金
	 */
	public Double getDeposit(){
		return this.deposit;
	}
	public void setDeposit(Double deposit){
		this.deposit = deposit;
	}
	/**
	 * 是否已备案
	 */
	public String getHasArchives(){
		return this.hasArchives;
	}
	public void setHasArchives(String hasArchives){
		this.hasArchives = hasArchives;
	}
	/**
	 * 备注
	 */
	public String getRemark(){
		return this.remark;
	}
	public void setRemark(String remark){
		this.remark = remark;
	}
	
	public String getContractState() {
		return contractState;
	}
	public void setContractState(String contractState) {
		this.contractState = contractState;
	}
	public String getContractChangeType() {
		return contractChangeType;
	}
	public void setContractChangeType(String contractChangeType) {
		this.contractChangeType = contractChangeType;
	}
	
	public String getReason() {
		return reason;
	}
	public void setReason(String reason) {
		this.reason = reason;
	}
	@Override
	public String toString() {
		return this.contractNum;
	}
	public Integer getBeforeDay() {
		return beforeDay;
	}
	public void setBeforeDay(Integer beforeDay) {
		this.beforeDay = beforeDay;
	}
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+08:00")
	public Date getInitPayEndDate() {
		return initPayEndDate;
	}
	public void setInitPayEndDate(Date initPayEndDate) {
		this.initPayEndDate = initPayEndDate;
	}
	public Double getRent() {
		return rent;
	}
	public void setRent(Double rent) {
		this.rent = rent;
	}
	public Date getAutoCalDate() {
		return autoCalDate;
	}
	public void setAutoCalDate(Date autoCalDate) {
		this.autoCalDate = autoCalDate;
	}
	public Boolean getHasInitPay() {
		return hasInitPay;
	}
	public void setHasInitPay(Boolean hasInitPay) {
		this.hasInitPay = hasInitPay;
	}
	public String getIncreaseHandle() {
		return increaseHandle;
	}
	public void setIncreaseHandle(String increaseHandle) {
		this.increaseHandle = increaseHandle;
	}
	public Date getSignDate() {
		return signDate;
	}
	public void setSignDate(Date signDate) {
		this.signDate = signDate;
	}
	public Double getArea() {
		return area;
	}
	public void setArea(Double area) {
		this.area = area;
	}
	public List<ContractAssetEntity> getContractAsset() {
		return contractAsset;
	}
	public void setContractAsset(List<ContractAssetEntity> contractAsset) {
		this.contractAsset = contractAsset;
	}
	public String getGroupOne() {
		return groupOne;
	}
	public void setGroupOne(String groupOne) {
		this.groupOne = groupOne;
	}
	public String getGroupTwo() {
		return groupTwo;
	}
	public void setGroupTwo(String groupTwo) {
		this.groupTwo = groupTwo;
	}
	public Double getGovPrice() {
		return govPrice;
	}
	public void setGovPrice(Double govPrice) {
		this.govPrice = govPrice;
	}
	public String getMarketPrice() {
		return marketPrice;
	}
	public void setMarketPrice(String marketPrice) {
		this.marketPrice = marketPrice;
	}
	
}
